<template>
  <dv-scroll-board
    :config="config"
    class="ps_w_h_100 ps-scroll-data"
    :key="key"
  />
</template>

<script setup>
import { ref, onMounted, computed, onUnmounted } from 'vue'
import isMobile from '@/utils/isMobile'

const key = ref(1)
const isMobile_ = ref(isMobile())
const props = defineProps({
  option: {
    type: Object,
    default: () => {
      return {}
    }
  },
  rowNum: {
    type: Number,
    default: 10
  },
  index: {
    type: Boolean,
    default: false
  },
  border: {
    type: Boolean,
    default: false
  },
  test: {
    type: Boolean,
    default: false
  }
})

const config = computed(() => {
  const _config = {
    header: props.option.header,
    data: props.option.data,
    rowNum: props.rowNum,
    index: props.index,
    align: [],
    headerBGC: 'rgba(0,0,0,0)',
    oddRowBGC: 'rgba(0,0,0,0)',
    evenRowBGC: 'rgba(0,0,0,0)',
    columnWidth: []
  }

  if (Object.prototype.hasOwnProperty.call(props.option, 'align')) {
    _config.align = props.option.align
  }

  if (Object.prototype.hasOwnProperty.call(props.option, 'columnWidth')) {
    if (props.test) {

      _config.columnWidth = isMobile_.value ? props.option.columnWidth : []

    } else {
      _config.columnWidth = props.option.columnWidth
    }
  }

  return _config
})

const border = computed(() => {
  return props.border ? '1px' : '0'
})

onMounted(() => {
  window.addEventListener('resize', () => {
    key.value++
  })
})

onUnmounted(() => {
  window.removeEventListener('resize', () => {
    key.value++
  })
})
</script>

<style scoped lang="scss">
.ps-scroll-data {
  :deep(.header) {
    border-bottom: v-bind(border) solid rgba(255, 255, 255, 0.3);
  }
}
</style>
